<?php
/**
 * Created by PhpStorm.
 * User: 1
 * Date: 2017/12/12
 * Time: 13:31
 */

namespace app\admin\model;


use think\Model;

class Reclass extends Model
{
    /**
     * 获取所有教师信息
     * @author 巫玉梅 <1120504614@qq.com>
     * @return
     */
    public function getAll(){
        $order="";
        $keywords   = trim(input('get.keywords'));
        if(!empty($keywords)){
            $where = ['u.full_name|u.tel|u.username|bld.lesson_sn' => ['like', "%{$keywords}%"]];
        }else{
            $where = [];
        }

        $data = $this
            ->alias('re')
            ->join('user u', 're.reclass_stu_id=u.id', 'LEFT')
            ->join('lesson bld', 're.reclass_les_id=bld.id', 'LEFT')
            ->field('re.*,re.reclass_status,u.full_name,
                    bld.lesson_name,bld.lesson_sn,bld.cost_type')
            ->where($where)
            ->order($order)
            ->select();
        if($data){
            foreach($data as $k => $v){
                $data[$k] = $v->toArray();
            }
        }
        return $data;
    }

    /**
     * 获取所有停课记录数
     * @author 巫玉梅 <1120504614@qq.com>
     * @return
     */
    public function getCount(){
        $order="";
        $keywords   = trim(input('get.keywords'));
        if(!empty($keywords)){
            $where = ['u.full_name|u.tel|u.username|bld.lesson_sn' => ['like', "%{$keywords}%"]];
        }else{
            $where = [];
        }
        $count = $this
            ->alias("re")
            ->join('user u', 're.reclass_stu_id=u.id', 'LEFT')
            ->join('lesson bld', 're.reclass_les_id=bld.id', 'LEFT')
            ->field('re.*,re.reclass_status,u.full_name,
                    bld.lesson_name,bld.lesson_sn,bld.cost_type')
            ->where($where)
            ->count();
        return $count;
    }

    /**
     * 查询单条信息
     * @author 巫玉梅 <1120504614@qq.com>
     * @return
     */
    public function getOne($where=""){
        $info = $this
            ->join('user u', 're.reclass_stu_id=u.id', 'LEFT')
            ->join('lesson bld', 're.reclass_les_id=bld.id', 'LEFT')
            ->field('re.*,re.reclass_status,u.full_name,
                    bld.lesson_name,bld.lesson_sn,bld.cost_type')
            ->where($where)
            ->find();
        if($info){
            $info = $info->toArray();
        }
        return $info;
    }
}